﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;

namespace MangaReader
{
    public partial class ContentForm : Form
    {
        public ContentForm()
        {
            InitializeComponent();
            this.Load += new EventHandler(ContentForm_Load);
        }
        Image[] images;
        int indexOfList = 0;
        void ContentForm_Load(object sender, EventArgs e)
        {
            // Construct the ImageList.
            imageList1 = new ImageList();

            // Set the ImageSize property to a larger size 
            // (the default is 16 x 16).
            imageList1.ImageSize = new Size(200, 200);

            foreach (string urlImage in MainForm.listImages)
            {
                WebClient webGetImage = new WebClient();
                //webGetImage.OpenReadAsync(new Uri(urlImage, UriKind.RelativeOrAbsolute));
                //webGetImage.OpenReadCompleted  +=new OpenReadCompletedEventHandler(webGetImage_OpenReadCompleted);
                webGetImage.DownloadDataAsync(new Uri(urlImage, UriKind.RelativeOrAbsolute));
                webGetImage.DownloadDataCompleted += new DownloadDataCompletedEventHandler(webGetImage_DownloadDataCompleted);
            }
        }

        void webGetImage_OpenReadCompleted(object sender, OpenReadCompletedEventArgs args)
        {
            imageList1.Images.Add(Image.FromStream(args.Result));
        }

        void webGetImage_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs args)
        {
            MemoryStream ms = new MemoryStream(args.Result);
            images[indexOfList] = Image.FromStream(ms);
        }

    }
}
